package com.ehome.poct.core.dao.mybatis;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ehome.core.util.BeanConvertUtil;
import com.ehome.poct.core.api.dto.check.gold.TestConfPoctStripMappingDTO;
import com.ehome.poct.core.api.dto.check.gold.TestConfPoctStripTypeDTO;
import com.ehome.poct.core.api.dto.check.gold.TestStripLimitClinicDTO;
import com.ehome.poct.core.dao.entity.check.TestConfPoctStripMappingDO;
import com.ehome.poct.core.dao.entity.check.TestConfPoctStripTypeDO;
import com.ehome.poct.core.dao.entity.check.TestStripLimitClinicDO;
import com.ehome.poct.core.dao.mybatis.mapper.TestConfPoctStripMappingMapper;
import com.ehome.poct.core.dao.mybatis.mapper.TestConfPoctStripTypeMapper;
import com.ehome.poct.core.dao.mybatis.mapper.TestStripLimitClinicMapper;
import com.ehome.poct.core.repository.check.GoldCheckRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author gyl
 * @since 2022/3/18 15:31
 **/
@Repository
public class GoldCheckRepositoryImpl implements GoldCheckRepository {

    @Autowired
    private TestStripLimitClinicMapper stripLimitClinicMapper;
    @Autowired
    private TestConfPoctStripTypeMapper confPoctStripTypeMapper;
    @Autowired
    private TestConfPoctStripMappingMapper confPoctStripMappingMapper;

    @Override
    public TestStripLimitClinicDTO getStripLimitByClinicId(Long clinicId) {
        TestStripLimitClinicDO testStripLimitClinicDO = stripLimitClinicMapper.selectOne(new QueryWrapper<TestStripLimitClinicDO>().lambda().eq(TestStripLimitClinicDO::getTermClinicId, clinicId));
        return BeanConvertUtil.convertBean(testStripLimitClinicDO, TestStripLimitClinicDTO.class);
    }

    @Override
    public TestConfPoctStripTypeDTO getPoctStripTypeByCode(Integer stripTypeCode) {
        TestConfPoctStripTypeDO testConfPoctStripTypeDO = confPoctStripTypeMapper.selectOne(new QueryWrapper<TestConfPoctStripTypeDO>().lambda().eq(TestConfPoctStripTypeDO::getTypeCode, stripTypeCode));
        return BeanConvertUtil.convertBean(testConfPoctStripTypeDO, TestConfPoctStripTypeDTO.class);
    }

    @Override
    public TestConfPoctStripMappingDTO getPoctStripMappingByCodeAndBatch(Integer stripTypeCode, Integer batch) {
        TestConfPoctStripMappingDO testConfPoctStripMappingDO = confPoctStripMappingMapper.selectOne(new QueryWrapper<TestConfPoctStripMappingDO>().lambda().eq(TestConfPoctStripMappingDO::getStripTypeCode, stripTypeCode)
                .eq(TestConfPoctStripMappingDO::getStripBatch, batch));
        return BeanConvertUtil.convertBean(testConfPoctStripMappingDO, TestConfPoctStripMappingDTO.class);
    }

}
